package com.yfp.goods.controller;

import com.yfp.common.core.domain.R;
import com.yfp.common.core.web.controller.BaseController;
import com.yfp.common.log.annotation.Log;
import com.yfp.common.log.enums.BusinessType;
import com.yfp.goods.domain.Goods;
import com.yfp.goods.domain.vo.ComboGoodsVo;
import com.yfp.goods.service.ComboGoodsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 套餐商品表(ComboGoods)表控制层
 *
 *
 * @since 2023-12-27 15:35:02
 */
@RestController
@RequestMapping("comboGoods")
@Tag(name = "套餐商品相关")
public class ComboGoodsController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ComboGoodsService comboGoodsService;


    @GetMapping("{comboId}")
    @Operation(summary = "通过套餐Id查询绑定的商品信息")
    public R<List<Goods>> queryByComboId(@PathVariable("comboId") String comboId) {
        return R.ok(this.comboGoodsService.queryByComboId(comboId));
    }

    /**
     * 新增数据
     *
     * @param comboGoodsVo 实体
     * @return 新增结果
     */
    @PostMapping
    @Operation(summary = "新增套餐商品数据")
    @Log(title = "套餐商品", businessType = BusinessType.INSERT)
    public R add(@RequestBody List<ComboGoodsVo> comboGoodsVo) {
        return this.comboGoodsService.insert(comboGoodsVo);
    }

    /**
     * 删除套餐商品数据
     *
     * @return 删除结果
     */
    @PutMapping("{comboGoodsId}")
    @Operation(summary = "删除套餐商品数据")
    @Log(title = "套餐商品", businessType = BusinessType.DELETE)
    public R edit( @PathVariable String comboGoodsId) {
        return this.comboGoodsService.deleteComboGoods(comboGoodsId) ? R.ok() : R.fail();
    }
}

